﻿@model Sheng.WeixinConstruction.Management.Shell.Models.LuckyTicket_PreparatoryViewModel

@{
    ViewBag.MainMenu = "Campaign";
    ViewBag.LeftMenu = "Donation";

    ViewBag.Title = "在线捐款";
    Layout = "~/Views/Shared/_Layout.cshtml";
 }


<script language="javascript">

    //当前页
    var _currentPage = 1;

    $(document).ready(function ()
    {
        if (_online == false)
            return;

        loadData();

    });

    function loadData(targetPage)
    {
        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        var args = new Object();
        args.Page = targetPage || 1;
        args.Status = 1;

        $.ajax({
            url: "/Api/Campaign/GetCampaign_DonationList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(args),
            success: function (data, status, jqXHR)
            {
                // alert(data);

                layer.close(loadLayerIndex);
                if (data.Success)
                {
                    var resultObj = data.Data;

                    _currentPage = resultObj.Page;

                    //alert(JSON.stringify(resultObj));
                    var gettpl = document.getElementById('tableTemplate').innerHTML;
                    laytpl(gettpl).render(resultObj.ItemList, function (html)
                    {
                        document.getElementById('divTableBodyContainer').innerHTML = html;
                    });

                    laypage({
                        skin: 'yahei',
                        cont: document.getElementById('divPagingContainer'),
                        pages: resultObj.TotalPage, //总页数
                        curr: resultObj.Page, //当前页
                        groups: 7, //连续显示分页数
                        jump: function (obj, first)
                        {
                            if (!first)
                            { //点击跳页触发函数自身，并传递当前页：obj.curr
                                loadData(obj.curr);
                            }
                        }
                    });

                } else
                {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function detail(id)
    {
        window.location.href = "/Campaign/DonationDetail?id=" + id;
    }

    function endCampaign(id)
    {
        var msg = "是否确认结束活动？"

        var confirmLayerIndex = layer.confirm(msg, {
            btn: ['确认', '取消'], //按钮
            shade: [0.4, '#393D49'],
            title: false,
            closeBtn: false,
            shift: _layerShift
        }, function ()
        {
            layer.close(confirmLayerIndex);

            var loadLayerIndex = layer.load(0, {
                shade: [0.2, '#fff']
            });

            $.ajax({
                url: "/Api/Campaign/EndCampaign?id=" + id,
                type: "POST",
                dataType: "json",
                success: function (data, status, jqXHR)
                {
                    if (data.Success)
                    {
                        if (data.Data == 0)
                        {
                            window.location.href = "/Campaign/Donation_End";
                        }
                        else
                        {
                            layer.close(loadLayerIndex);
                            switch (data.Data)
                            {
                                case 1:
                                    layerAlert("此活动已经是结束过的活动。");
                                case 2:
                                    layerAlert("此活动还没有开始。");
                                default:
                                    layerAlert("开始失败");
                            }
                        }

                    } else
                    {
                        layer.close(loadLayerIndex);
                        layerAlert(data.Message);
                    }
                },
                error: function (xmlHttpRequest)
                {
                    layer.close(loadLayerIndex);
                    alert("Error: " + xmlHttpRequest.status);
                }
            });
        });
    }

</script>

<script id="tableTemplate" type="text/html">


    {{# for(var i = 0, len = d.length; i < len; i++){ }}
    <div class="divBorder_lightgray" style="margin-top:20px; padding-bottom:10px;">
        <div style="height:40px; line-height:40px; background-color:#F5F5F8; padding-left:20px;">
            <a href="javascript:void(0)" onclick="detail('{{ d[i].Id }}')">{{ d[i].Name }}</a>
        </div>
        <div style="margin-left:20px; margin-right:20px;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td valign="top">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-top:20px;">
                            <tr>
                                <td width="50%" height="36" valign="top">创建时间：{{ d[i].CreateTime}}</td>
                                <td width="50%" valign="top">&nbsp;</td>
                            </tr>
                            <tr>
                                <td width="50%" height="36" valign="top">开始时间：{{ d[i].StartTime}}</td>
                                <td width="50%" valign="top">&nbsp;</td>
                            </tr>
                            <tr>
                                <td height="36" valign="top">创建者：{{ d[i].CreateUserName}}</td>
                                <td valign="top">仅关注者可参与：{{# if(d[i].OnlyMember == true){ }}是{{# }else{ }}否{{# } }}</td>
                            </tr>
                            <tr>
                                <td colspan="2" valign="top">备注：{{ d[i].Remark}}</td>
                            </tr>
                        </table>

                    </td>
                    <td width="280" align="right" valign="top">
                        <img style="max-width:240px;" src="{{ d[i].ImageUrl}}" />
                    </td>
                </tr>
            </table>
        </div>
        <div class="divDotLine" style="margin-top:20px;margin-left:20px; margin-right:20px;"></div>
        <div style="margin-top:10px;margin-left:20px; margin-right:20px;">
            <div style="float:right">
                <input type="button" class="btn_red" value="结 束" onclick="endCampaign('{{ d[i].Id }}')" />
            </div>
            <div style="clear:both">
            </div>
        </div>
    </div>
    {{# } }}


</script>

@*<div id="divContentTips">
        配置公众平台账号，才能让你的店铺与微信公众号关联。   <a href="#">查看详细&gt;</a>
    </div>*@

<div style=" margin-top:20px;">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="td_ContentTab_active" style="width:200px;">进行中（@Model.CampaignCount.OngoingCount）</td>
            <td class="td_ContentTab" style="width:200px;"><a href="/Campaign/Donation_Preparatory" class="a_black_16">未开始（@Model.CampaignCount.PreparatoryCount）</a></td>
            <td class="td_ContentTab" style="width:200px;"><a href="/Campaign/Donation_End" class="a_black_16">已结束（@Model.CampaignCount.EndCount）</a></td>
            <td align="right">
                <input name="btnCreate" type="button" class="btn_blue" id="btnCreate" value="发起活动" style="margin-right:0px;" onclick="goUrl('@Url.Action("DonationEidt")')" />
            </td>
        </tr>
        <tr>
            <td colspan="4" bgcolor="#EEEEEE" height="2"></td>
        </tr>
    </table>
</div>

<div id="divTableBodyContainer">


</div>


<div id="divPagingContainer" style=" margin-top:20px; margin-bottom:20px;text-align:right; ">

</div>